package com.wang.leetcode;

public class Solution111 {

    public class TreeNode {
       int val;
       TreeNode left;
       TreeNode right;
       TreeNode() {}
       TreeNode(int val) { this.val = val; }
       TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
    //二叉树的最小深度  递归  111
    public int minDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        if(root.left == null && root.right != null) {
            return 1 + minDepth(root.right);
        }
        if(root.right == null && root.left != null) {
            return 1 + minDepth(root.left);
        }

        return  1 + Math.min(minDepth(root.right),minDepth(root.left));
    }
    //二叉树的最大深度  递归 104
    public int maxDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);
        return Math.max(leftDepth,rightDepth) + 1;
    }

}
